package cn.iocoder.yudao.module.handguard.service.userbasetable16;

import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.math.BigDecimal;
import java.util.*;
import cn.iocoder.yudao.module.handguard.controller.app.userbasetable16.vo.*;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable16.UserBaseTable16DO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.handguard.convert.userbasetable16.UserBaseTable16Convert;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable16.UserBaseTable16Mapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.handguard.enums.ErrorCodeConstants.*;

/**
 * 完成住宅二次抵押 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class UserBaseTable16ServiceImpl implements UserBaseTable16Service {

    @Resource
    private UserBaseTable16Mapper userBaseTable16Mapper;

    @Override
    public Long createUserBaseTable16(UserBaseTable16CreateReqVO createReqVO) {
        // 插入
        UserBaseTable16DO userBaseTable16 = UserBaseTable16Convert.INSTANCE.convert(createReqVO);
        userBaseTable16Mapper.insert(userBaseTable16);
        // 返回
        return userBaseTable16.getId();
    }

    @Override
    public void updateUserBaseTable16(UserBaseTable16UpdateReqVO updateReqVO) {
        // 校验存在
        validateUserBaseTable16Exists(updateReqVO.getId());
        // 更新
        UserBaseTable16DO updateObj = UserBaseTable16Convert.INSTANCE.convert(updateReqVO);
        userBaseTable16Mapper.updateById(updateObj);
    }

    @Override
    public void deleteUserBaseTable16(Long id) {
        // 校验存在
        validateUserBaseTable16Exists(id);
        // 删除
        userBaseTable16Mapper.deleteById(id);
    }

    private void validateUserBaseTable16Exists(Long id) {
        if (userBaseTable16Mapper.selectById(id) == null) {
            throw exception(USER_BASE_TABLE16_NOT_EXISTS);
        }
    }

    @Override
    public UserBaseTable16DO getUserBaseTable16(Long id) {
        return userBaseTable16Mapper.selectById(id);
    }

    @Override
    public List<UserBaseTable16DO> getUserBaseTable16List(Long userId) {
        LambdaQueryWrapper<UserBaseTable16DO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserBaseTable16DO::getUserId,userId);
        return userBaseTable16Mapper.selectList(queryWrapper);
    }

    @Override
    public PageResult<UserBaseTable16DO> getUserBaseTable16Page(UserBaseTable16PageReqVO pageReqVO) {
        return userBaseTable16Mapper.selectPage(pageReqVO);
    }

    @Override
    public List<UserBaseTable16DO> getUserBaseTable16List(UserBaseTable16ExportReqVO exportReqVO) {
        return userBaseTable16Mapper.selectList(exportReqVO);
    }

}
